package com.zj.core.base

import android.annotation.SuppressLint
import android.content.Context
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import com.zj.core.R
import android.widget.LinearLayout
import com.zj.core.ui.TitleBarActivityUi
import org.jetbrains.anko.setContentView


@SuppressLint("Registered")
abstract class TitleBarActivity: BaseActivity(),View.OnClickListener{
    lateinit var titleBaseUi: TitleBarActivityUi
    var baseContext: AppCompatActivity?=null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        titleBaseUi= TitleBarActivityUi(this)
        titleBaseUi.setContentView(this)

        setTitleBarVisible(View.VISIBLE)
        setTitleBarParams(titleBaseUi.base_bar_bg_clt)
        onCreate(titleBaseUi.parent_view)

        baseContext=this
        initView()
    }

    abstract fun onCreate(groupView:LinearLayout): View?

    abstract fun initView()

    override fun onClick(v: View?) {
        when(v?.id){
            R.id.base_bar_back_img ->{
                finish()
            }
        }
    }

    override fun setTitleBarParams(view: View) {
        view.layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 100)
    }

    /**
     * 设置标题栏隐藏
     */
    fun setTitleBarVisible(visible:Int){
        titleBaseUi.base_bar_bg_clt.visibility=visible
    }

    fun setRightViewListener(click: View.OnClickListener?){
        if(click!=null){
            titleBaseUi.float_action_bu.setOnClickListener(click)
        }
    }

    fun setTitleText(titleName:String){
        titleBaseUi.base_bar_title_tv.text=titleName
    }

    fun setRightViewText(titleName:String){
        titleBaseUi.float_action_bu.text=titleName
    }

    fun setRightViewVisible(visible:Int){
        titleBaseUi.float_action_bu.visibility=visible
    }
}